<template>
  <div>
    <van-nav-bar title="添加银行卡" left-arrow @click-left="$router.back()"/>
    <div class="initiate_main_left">
        <div class="bank_box">
            <div class="bank_desc">
                <label class="label">银行卡号</label>
                <span class="bank_desc_item"><input placeholder="请输入"  v-model="requestData.code" /></span>
            </div>
            <div class="bank_desc">
                <label class="label">开户银行</label>
                <span class="bank_desc_item">
                    <van-field readonly clickable :value="requestData.openBank" placeholder="请选择" @click="showPicker = true"/>
                </span>
                <van-icon name="arrow" />
            </div>
            <div class="bank_desc">
                <label class="label">预留手机号</label>
                <span class="bank_desc_item">
                    <input maxlength="11" @keyup="requestData.cellphone=requestData.cellphone.replace(/[^0-9]/g, '')" placeholder="请输入" type="text" @blur="regPhone(requestData.cellphone)" v-model="requestData.cellphone" />
                </span>
            </div>
            <!-- <div class="bank_desc">
                <label class="label">验&nbsp;&nbsp;证&nbsp;&nbsp;码</label>
                <span class="bank_desc_item"><gz-code-input :requestData="requestData" placeholder="请输入"></gz-code-input></span>
            </div> -->
        </div>
    </div>
    <div class="bottom_btn" @click="releaseShowClick">下一步</div>
    <van-popup v-model="showPicker" position="bottom">
        <van-picker show-toolbar :columns="columns" v-model="openBankValue" @cancel="showPicker = false" @confirm="onConfirm" />
    </van-popup>
  </div>
</template>
<script>
export default {
    name: "addBankCard",
    data() {
        return {
            requestData: {
                // mateName: '11111',
                // tel: '',
                // instId: '11111'
            },
            showPicker: false,
            columns: ['建设银行', '邮政银行', '民生'],
            openBankValue: ''
        }
    },
    components: {  },
    mounted() {
    },
	created () {
	},
	computed: {

	},
    methods: {
        releaseShowClick(){
            if(!this.requestData.code || !this.requestData.openBank || !this.requestData.cellphone){
                this.$toast({
                    icon: 'warning',
                    message: "请完善表单数据！"
                });
                return;
            }else{
                if( /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/gi.test(this.requestData.cellphone.trim()) ){
                }else{
                    this.$toast({
                        icon: 'warning',
                        message: "请输入正确手机号！"
                    });
                    return;
                }
            }
            this.$toast.loading({
                duration: 0, // 持续展示 toast
                forbidClick: true,
                message: '提交中，请稍后'
            });
            var userMsgJson = localStorage.getItem("userMsg");
            var userMsgJson1 = JSON.parse(userMsgJson);
            this.requestData.clientId = userMsgJson1.user.account;  //  客户号
            this.requestData.clientName = userMsgJson1.user.fullname;   //客户名称
            this.baseService.post(this.__ctx + '/plugin/mobileBusiCenter/bankCardSave', this.requestData).then(res => {
                this.$toast.clear();
                if (res.isOk) {
                    // this.$toast({
                    //     icon: 'success',
                    //     message: '银行卡绑定成功'
                    // });
                    this.$router.push({path: '/loanPage/addBankCardCode', query: {id: res.data.id, phone: this.requestData.cellphone}});
                } else {
                    this.$toast({
                        icon: 'warning',
                        message: res.msg
                    });
                }
            }, function (status) {
                this.$toast.clear();
                if (status == !0) {
                    this.$toast({
                        icon: 'warning',
                        message: '加载失败！' + status
                    });
                }
            });
        },
        handleChange(e){
			this.show = false;
		},
        onConfirm(value) {
            this.openBankValue = value;
            this.requestData.openBank = value;
            console.log(value, this.openBankValue, this.requestData.openBank)
            this.showPicker = false;
        },
        regPhone(phone) {
            this.requestData.cellphone = phone.replace(/[^0-9]/g, '');
        },
    }
  }
</script>

<style scoped lang="less">
/deep/.van-nav-bar{
  .van-nav-bar__content{
    height: 4.4rem;
    line-height: 2rem;
    .van-icon{
      color: rgb(50, 50, 51);
      font-size: 2rem;
    }
    .van-nav-bar__title{
      font-size: 1.8rem;
    }
  }
}
[class*=van-hairline]::after{
  border: 0;
}
.initiate_main_left {
    padding: 1.2rem 1.2rem 0;
    overflow-y: auto;

    .bank_box{
        background: #ffffff;
        border-radius: 1.2rem;
        padding: 0 1.6rem;
        .bank_desc{
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: rgb(29, 33, 41);
            font-family: HarmonyOS Sans SC;
            padding: 0.8rem 0;
            border-bottom: 1px solid rgba(229, 230, 235, 0.5);
            .label{
                font-size: 1.6rem;
                line-height: 1.8rem;
            }
            .bank_desc_item{
                // color: rgb(201, 205, 212);
                width: 80%;
                font-size: 1.6rem;
                font-weight: 400;
                line-height: 1.6rem;
                letter-spacing: 0px;
                flex: 1;
                input{
                    width: 100%;
                    height: 4rem;
                    text-align: right;
                    border: 0;
                }

                /deep/.van-cell{
                    padding: 0;
                    font-size: 1.6rem;
                    .van-field__control{
                        height: 4rem;
                        text-align: right;
                    }
                }
            }
            .van-icon{
                color: rgb(201, 205, 212);
            }
        }
    }
}
.bottom_btn{
    width: calc(~'100% - 2.4rem');
    height: 4.4rem;
    margin: 1.8rem 1.2rem;
    background: linear-gradient(270.00deg, var(--primary-color), var(--gradient2-color));
    border-radius: 4rem;
    color: rgb(255, 255, 255);
    font-family: HarmonyOS Sans SC;
    font-size: 1.6rem;
    font-weight: 500;
    line-height: 4.4rem;
    letter-spacing: 0%;
    text-align: center;
    position: absolute;
    bottom: 0.6rem;
    left: 0;
}
</style>
<style>
.initiate_main_left .bank_desc .not-border .input-box{
    input{
        text-align: right;
    }
    a{
        color: var(--primary-color)!important;
    }
}
</style>